package com.samsungmobile.common.channel;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ServletChannel extends HttpServlet {

	public ServletChannel() {
		super();
	}
	
	protected void doService(HttpServletRequest req, HttpServletResponse res) {

		String execName = null;
	    try {
	 
			execName = "com.samsungmobile." + req.getParameter("class");
            System.out.println("execName:"+execName);
			
			if (execName == null || execName.trim().equals("") || execName.trim().equals("null")) {
				System.out.println("fail in ServletChannel : 'class' not specified.");
			}

			((ServletRun)Class.forName(execName).newInstance()).execute(req, res);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void doGet(HttpServletRequest req, HttpServletResponse res)
		throws ServletException, IOException {
			doPost(req,res);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse res)
		throws ServletException, IOException {

		    try{
			    doService(req, res);
		    }catch(Exception e){ 
		    	e.printStackTrace();
		    }
	}
}
